<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>楼盘展示管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			
		});
		function hang(h,obj){
			var oInput=document.getElementsByName("hang"+h);
			 for (var i=0;i<oInput.length;i++){
			 	oInput[i].checked=obj.checked;
			}
		}
		function lie(l,obj){
			var oInput= $("[title='lie"+l+"']");
			 for (var i=0;i<oInput.length;i++){
			 	oInput[i].checked=obj.checked;
			}
		}
		//转换字节码
			function toUnicode(s){ 
	          return s.replace(/([\u4E00-\u9FA5]|[\uFE30-\uFFA0])/g,function(newStr){
	            return "\\u" + newStr.charCodeAt(0).toString(16); 
	　　　　　　}); 
	　　　　} 
		
		function shengcheng(){
			var bottom = $('[name="bottom"]').val();
			var topfloor =$('[name="topfloor"]').val();
			var	roomnum =$('[name="roomnum"]').val();
			if(bottom == '' || topfloor == '' || roomnum == ''){
				alert('请填写完整');
				return;
			}
			location='${ctx}/ta/xtLoupan/insertRoom?bottom='+bottom+'&topfloor='+topfloor+'&roomnum='+roomnum;
		}
		
		function del(){
			var de = new Array();
			var c = 0;
			var oInput= $("[alt='d']");
			 for (var i=0;i<oInput.length;i++){
				 if(oInput[i].checked){
					 de[c] = oInput[i].id;
					 c ++;
				 }
			}
			location = "${ctx}/ta/xtLoupan/delete?de="+de;
		}
		
		function fan(){
			var oInput= $("[alt='d']");
			 for (var i=0;i<oInput.length;i++){
				 if(oInput[i].checked){
					 oInput[i].checked = false;
				 }else{
					 oInput[i].checked = true;
				 }
			}
		}
		
		function piliang(di){
			var ce = new Array();
			var d = 0;
			var oInput= $("[alt='d']");
				for (var i=0;i<oInput.length;i++){
					if(oInput[i].checked){
						ce[d] = oInput[i].id;
					 d ++;
				 }
			}
			var fwlx =  toUnicode($('[name="fwlx"]').val());
			var fx =  toUnicode($('[name="fx"]').val());
			var ycjzmj =  $('[name="ycjzmj"]').val();
			if(ycjzmj == ''){
				alert('请填写预测建筑面积');
				return;
			}
			var scjzmj =  $('[name="scjzmj"]').val();
			if(scjzmj == ''){
				alert('请填写实际建筑面积');
				return;
			}
			location = "${ctx}/ta/xtLoupan/update?str="+ce+"&fwlx="+fwlx+"&fx="+fx+"&ycjzmj="+ycjzmj+"&scjzmj="+scjzmj;
		}
		
		function remark(fh) {
			$.ajax({
				type:"post",
				url: "${ctx}/ta/xtLoupan/getx",
				data:{"fh":fh},
				dateType:"json",
				success:function(result){
					if(result != null){
						$('[name="lch0"]').val(result.lch);
						$('[name="fho"]').val(result.fh);
					
						$("[name='fwlxo']").val(result.fwlx);
						$("#fxtd").find(".select2-chosen").html(result.fwlx);
						$("[name='fxo']").val(result.fx);
						$("#hxtd").find(".select2-chosen").html(result.fx);
						
						$('[name="ycjzmjo"]').val(result.ycjzmj);
						$('[name="scjzmjo"]').val(result.scjzmj);
						$("#remark").css("display", "block");
					}
				},
				error:function(date){
					alert(JSON.stringify(date));
				}
			}); 
		}
		function remarkOff() {
			$("#remark").css("display", "none");
		}
		function upd(){
			var fwlx =  $('[name="fwlxo"]').val();
			var fx =  $('[name="fxo"]').val();
			var fh =  $('[name="fho"]').val();
			var ycjzmj =  $('[name="ycjzmjo"]').val();
			var scjzmj =  $('[name="scjzmjo"]').val();
			$.ajax({
				type:"post",
				url: "${ctx}/ta/xtLoupan/upd",
				data:{"fh":fh,"fwlx":fwlx,"fx":fx,"ycjzmj":ycjzmj,"scjzmj":scjzmj},
				dateType:"json",
				success:function(result){
					$("#remark").css("display", "none");
				},
				error:function(date){
					alert(JSON.stringify(date));
				}
			}); 
		}
	</script>
	<style type="text/css">
#remark {
	margin-left: 20%;
	margin-top: 10%;
	width: 400px;
	height: 250px;
	background-color: #fff;
	border: 1px solid #ccc;
	position: fixed;
	left: 0;
	top: 0;
}
</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/ta/xtLoupan/">楼盘信息</a></li>
	</ul>
	<sys:message content="${message}"/>
	<c:if test="${lp != null}">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
			<tr>
				<th align="center">楼盘展示</th>
			</tr>
			<tr>
				<td></td>
				<c:forEach begin="1" var="i" end="${lc}">
					<td><input onclick="lie(${i},this)" type="checkbox" /></td>
				</c:forEach>
			</tr>
			<c:if test="${lp != null}">
				<c:forEach var="l" items="${louceng}">
					<tr>
						<td><input name="h${l}" onchange="hang(${l},this)" type="checkbox" />${l}</td>
						<c:forEach items="${lp}" var="lp">
							<c:if test="${lp.lch == l}">
								<td><input alt="d" name="hang${l}" title="lie${lp.nd}" id="${lp.fh}" type="checkbox" /><a href="javascript:remark(${lp.fh})">${lp.fh}</a></td>
							</c:if>
						</c:forEach>
					</tr>
				</c:forEach>
			</c:if>
	</table>
	</c:if>
	<span><input style="background-color: red;border: none;width: 10px;height: 15px;" readonly="readonly" />安置房源面积小于被征收面积</span>
	<div align="center">
		<table height="220px" align="left" width="50%" border="1px">
			<thead>
				<tr>
					<th colspan="3" align="center">生成楼盘信息</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td rowspan="2">楼层数</td>
					<td>最底层：<input name="bottom" value="1" /></td>
					<td></td>
				</tr>
				<tr>
					<td>最高层：<input name="topfloor"/></td>
					<td></td>
				</tr>
				<tr>
					<td>每层房间数</td>
					<td><input name="roomnum"/></td>
					<td></td>
				</tr>
				<tr>
					<td colspan="3" align="center">
						<input type="button" onclick="shengcheng()" value="生成" />
						<input type="button" onclick="del()" value="删除" />
						<input type="button" onclick="location='${ctx}/ta/xtLoupan/deleteAll'" value="全删" />
						<input type="button" onclick="history.go(-1)" value="返回" />
					</td>
				</tr>
				<tr>
					<td colspan="3">
						1，当只生成一层时，最底层与最高层填写数据一样。<br/>
						2，室号当生成为不以01房间号开始的情况下使用。<br/>
						<span style="color: red;">3，房间号须从低开始生成，需要用生成与删除配合。</span>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
	<div align="center">
		<table height="220px" align="right" width="50%" border="1px">
			<thead>
				<tr>
					<th colspan="3" align="center">批量设置</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td>房屋类型：</td>
					<td>
						<select name="fwlx" style="width: 100px">
							<c:forEach items="${lx}" var="lx">
								<option value="${lx}">${lx}</option>
							</c:forEach>
						</select>
					</td>
				</tr>
				<tr>
					<td>户型：</td>
					<td>
						<select name="fx" style="width: 100px">
							<c:forEach items="${hx}" var="hx">
								<option value="${hx}">${hx}</option>
							</c:forEach>
						</select>
					</td>
				</tr>
				<tr>
					<td>预测建筑面积：</td>
					<td><input name="ycjzmj"/>平方米</td>
				</tr>
				<tr>
					<td>实测建筑面积：</td>
					<td><input name="scjzmj"/>平方米</td>
				</tr>
				<tr>
					<td colspan="3" align="center">
						<input type="button" onclick="fan()" value="反选" />
						<input type="button" onclick="piliang()" value="设置" />
					</td>
				</tr>
			</tbody>
		</table>
	</div>
	
	<div id="remark" <c:if test="${b == 'block'}">style="display: block;"</c:if><c:if test="${b != 'block'}">style="display: none;"</c:if>>
		<h4 align="center" style="margin-top: 2%">房屋信息：</h4>
		<input type="button" value="X"
			style="float: right; margin-top: -28px; background-color: #fff; border: none;"
			onclick="remarkOff()" />
		<div align="left" style="width: 360px; height: 200px; border: 1px solid #ccc; margin-left: 5%; margin-top: 1%">
			<table>
				<tr>
					<td>楼层号：</td>
					<td><input readonly="readonly" name="lch0" value="${xtloupan.lch}" /></td>
				</tr>
				<tr>
					<td>房间号：</td>
					<td><input readonly="readonly"  name="fho" value="${xtloupan.fh}" /></td>
				</tr>
				<tr>
					<td>房屋类型：</td>
					<td id="fxtd">
						<select name="fwlxo" style="width: 100px">
							<c:forEach items="${lx}" var="lx">
								<option value="${lx}">${lx}</option>
							</c:forEach>
						</select>
					</td>
				</tr>
				<tr>
					<td>户型：</td>
					<td id="hxtd">
						<select name="fxo" style="width: 100px">
							<c:forEach items="${hx}" var="hx">
								<option value="${hx}">${hx}</option>
							</c:forEach>
						</select>
					</td>
				</tr>
				<tr>
					<td>预测建筑面积：</td>
					<td><input name="ycjzmjo" value="${xtloupan.ycjzmj}"/>平方米</td>
				</tr>
				<tr>
					<td>实测建筑面积：</td>
					<td><input name="scjzmjo" value="${xtloupan.scjzmj}"/>平方米</td>
				</tr>
			</table>
			<center><input onclick="upd()" type="button" value="保存" /></center>
		</div>
	</div>
</body>
</html>